package com.huirui.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huirui.server.mapper.CarouselMapper;
import com.huirui.server.pojo.entity.Carousel;
import com.huirui.server.pojo.vo.CarouselVo;
import com.huirui.server.service.CarouselService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yujun
 * @description 针对表【t_carousel(微信小程序首页轮播图)】的数据库操作Service实现
 * @createDate 2025-09-24 16:07:27
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel>
        implements CarouselService {


    @Override
    public List<CarouselVo> listHomePageCarousel() {
        return baseMapper.getAllEnabledCarousel();
    }

    @Override
    public List<CarouselVo> getAllCarousel() {
        return baseMapper.getAllCarousel();
    }

    @Override
    public void addCarousel(CarouselVo carouselVo) {
        Carousel carousel = new Carousel();
        carousel.setStatus(1);
        carousel.setCreateTime(LocalDateTime.now());
        carousel.setUpdateTime(LocalDateTime.now());
        carousel.setTitle(carouselVo.getTitle());
        carousel.setSort(carouselVo.getSort());
        carousel.setImageUrl(carouselVo.getCarouselImage());
        carousel.setLinkType(carouselVo.getType());
        carousel.setLinkValue(carouselVo.getLinkValue());
        carousel.setStatus(carouselVo.getStatus());
        save(carousel);
    }

    @Override
    public void updateCarousel(CarouselVo carouselVo) {
        lambdaUpdate()
                .eq(Carousel::getId, carouselVo.getId())
                .set(Carousel::getStatus, carouselVo.getStatus())
                .set(Carousel::getUpdateTime, LocalDateTime.now())
                .set(Carousel::getSort, carouselVo.getSort())
                .set(Carousel::getTitle, carouselVo.getTitle())
                .set(Carousel::getLinkValue, carouselVo.getLinkValue())
                .set(Carousel::getLinkType, carouselVo.getType())
                .set(Carousel::getImageUrl, carouselVo.getCarouselImage())
                .update();
    }
}




